/*
 * File:   main.cpp
 * Author: Kreyl
 *
 * Created on May 27, 2011, 6:37 PM
 */

#include "stm32f10x.h"

#include "main.h"
#include "kl_lib.h"
#include "led.h"
#include "flashloader_support.h"



// Prototypes
void GeneralInit(void);

bool KWP = false;
Led_t PowerLed;

// ============================ Implementation ================================
int main(void) {
    GeneralInit();

    PowerLed.On();

    uint32_t Tmr;

    // ==== Main cycle ====
    while(1) {
        if(Delay.Elapsed(&Tmr, 50)){
            if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) && !KWP){
                PowerLed.Toggle();
//                JumpToFlashLdr();
                KWP = true;
            }
            if (!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) && KWP){
                KWP = false;
            }
        }
        Uart.Task();
    } // while(1)
}

void GeneralInit(void) {
    // Init delay
    Delay.Init();
    PowerLed.Init(GPIOC, 9);  // Led
    klPinSetup(GPIOA, 0, pmInFloating, ps50MHz); // Button

    Uart.Init(500000);
    Uart.Printf(" Urelesta v.%u\r", CURRENT_FIRMWARE_VERSION);
}

void CmdUnit_t::NewCmdHandler(){
//  Place here
}
